package cc;

import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class WordToPdfConverter {
    private final static IConverter converter = LocalConverter.builder().build();

    public static void main(String[] args) {
        File inputWord = new File("template.doc"); // 输入的Word文档路径
        File outputPdf = new File("output.pdf"); // 输出的PDF路径

        try (FileInputStream input = new FileInputStream(inputWord); FileOutputStream output = new FileOutputStream(outputPdf)) {
            converter.convert(input).as(DocumentType.DOCX)
                    .to(output).as(DocumentType.PDF)
                    .execute();
            System.out.println("转换完成！");
        } catch (IOException e) {
            System.out.println("转换失败！");
        }
    }
}